#include<iostream>
#include<string>

using namespace std;

class str {
    private:
        char *st;
    public:
        str(char *s);
        str(str& s);
        str& operator=(str& a);
        str& operator=(char* s);
        void print() {
            cout << st << endl;
        }
        ~str() {
            delete []st;
        }
};

str::str(char *s) {
    st = new char[strlen(s) + 1];
    strcpy(st,s);
}

str::str(str& s) {
    st = new char[strlen(s.st) + 1];
    strcpy(st,s.st);
}

str& str::operator=(str& a) {
    if (this == &a) {
        return *this;
    }

    delete []st;
    st = new char[strlen(a.st)+1];
    strcpy(st,a.st);
    return *this;
}

str& str::operator=(char *a) {
    delete []st;
    st = new char[strlen(a) + 1];
    strcpy(st,a);
    return *this;
}

int main() {
    str s1("We"),s2("They"),s3(s1);
    s1.print();
    s2.print();
    s3.print();
    s2=s1=s3;
    cout << "after s2=s1=s3" << endl;
    s1.print();
    s2.print();
    s3.print();
    s3 = "Go home!";
    cout << "after s = \"Go home!\"" << endl;
    s1.print();
    s2.print();
    s3.print();
    s3 = s3;
    cout << "s3 = s3" << endl;
    s1.print();
    s2.print();
    s3.print();
    return 0;
}
